﻿using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Web_App___AWS_ELB_Monitor
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


            routes.MapRoute(
                "EC2Instance",
                "ec2/{instanceId}",
                new {controller = "EC2Monitor", action = "Instance"}
                );

            routes.MapRoute(
                "EC2Default",
                "ec2/{action}/{instanceId}",
                new {controller = "EC2Monitor", action = "Instance"}
                );


            //routes.MapRoute("LoadBalancers",
            routes.MapRoute(
                "ELBRandom", // Route name
                "elb/random", // URL with parameters
                new {controller = "ELBMonitor", action = "Random"} // Parameter defaults
                );

            routes.MapRoute(
                "ELBDefault", // Route name
                "elb/{loadBalancerName}", // URL with parameters
                new {controller = "ELBMonitor", action = "LoadBalancer"} // Parameter defaults
                );

            routes.MapRoute(
                "ELBHealth", // Route name
                "elb/{loadBalancerName}/preview", // URL with parameters
                new {controller = "ELBMonitor", action = "HealthPreview"} // Parameter defaults
                );

            routes.MapRoute(
                "ASDashboard",
                "autoscale/{autoScaleGroupName}",
                new {controller = "AS", action = "AutoScaleGroup"}
                );


            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{loadBalancerName}", // URL with parameters
                new {controller = "Home", action = "Index", loadBalancerName = UrlParameter.Optional}
                // Parameter defaults
                );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}